package leetcode;

/**
 * description:
 * author:张腾
 * date:2021-06-10
 */
public class leetcode110_2 {
    public boolean isBalanced(TreeNode root) {
        if (root==null) return true;
        return reCur(root)==-1?false:true;
    }

    public int reCur(TreeNode root){
        if (root==null) return 0;

        int left = reCur(root.left);
        if (left == -1) return -1;
        int right = reCur(root.right);
        if (right == -1) return -1;

        return Math.abs(left - right) < 2 ? Math.max(left, right) + 1 : -1;
    }

}
